package com.panfeng.xcloud.boss.provider.assets.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.panfeng.xcloud.boss.provider.assets.dto.request.QueryUserWalletInfoPageReqDTO;
import com.panfeng.xcloud.boss.provider.assets.dto.request.UpdateUserWalletInfoReqDTO;
import com.panfeng.xcloud.boss.provider.assets.dto.request.WithdrawReqDTO;
import com.panfeng.xcloud.boss.provider.assets.dto.response.QueryUserWalletInfoPageRespDTO;
import com.panfeng.xcloud.boss.provider.assets.dto.response.UpdateUserWalletInfoRespDTO;
import com.panfeng.xcloud.boss.provider.assets.dto.response.WithdrawRespDTO;
import com.panfeng.xcloud.boss.provider.assets.service.IUserWalletInfoService;
import com.panfeng.xcloud.boss.provider.assets.web.vo.request.QueryUserWalletInfoPageReqVO;
import com.panfeng.xcloud.boss.provider.assets.web.vo.request.UpdateUserWalletInfoReqVO;
import com.panfeng.xcloud.boss.provider.assets.web.vo.request.WithdrawReqVO;
import com.panfeng.xcloud.boss.provider.assets.web.vo.response.QueryUserWalletInfoPageRespVO;
import com.panfeng.xcloud.boss.provider.assets.web.vo.response.UpdateUserWalletInfoRespVO;
import com.panfeng.xcloud.boss.provider.assets.web.vo.response.WithdrawRespVO;
import com.panfeng.xcloud.common.core.page.PageResponse;
import com.panfeng.xcloud.common.core.utils.ConvertUtils;
import com.panfeng.xcloud.common.core.web.vo.PageResponseVO;
import com.panfeng.xcloud.common.core.web.vo.ResponseVO;
import com.panfeng.xcloud.common.security.annotation.MethodValidate;
import com.panfeng.xcloud.common.security.annotation.NotNeedAccess;
import com.panfeng.xcloud.common.security.web.support.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 钱包信息相关模块
 *
 * @author xiaobo
 * @version 1.0
 * @since 2021-03-23
 */
//@ApiIgnore
@RestController
@RequestMapping("assets/userWalletInfo")
@Api(tags = {"钱包信息相关模块"})
@Slf4j
public class UserWalletInfoController extends BaseController {

    @Autowired
    private IUserWalletInfoService iUserWalletInfoService;

    /**
     * 查询钱包信息相关
     *
     * @param queryUserWalletInfoPageReqVO
     * @param bindingResult
     * @return
     */
    @NotNeedAccess
    @MethodValidate
    @PostMapping(value = "/queryUserWalletInfo", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询钱包信息相关(肖博)", httpMethod = "POST", notes = "查询钱包信息相关(肖博)")
    public ResponseVO<PageResponseVO<QueryUserWalletInfoPageRespVO>> queryWalletAssets(@RequestBody @Valid QueryUserWalletInfoPageReqVO queryUserWalletInfoPageReqVO, BindingResult bindingResult) {
        logger.info(">>>> 当前queryUserWalletInfo请求参数：{} <<<", (null != queryUserWalletInfoPageReqVO ? JSONObject.toJSONString(queryUserWalletInfoPageReqVO) : ""));
        QueryUserWalletInfoPageReqDTO queryUserWalletInfoPageReqDTO = ConvertUtils.convert(queryUserWalletInfoPageReqVO, QueryUserWalletInfoPageReqDTO.class);
        PageResponse<QueryUserWalletInfoPageRespDTO> pageDTO = iUserWalletInfoService.queryUserWalletInfo(queryUserWalletInfoPageReqDTO);
        PageResponseVO<QueryUserWalletInfoPageRespVO> pageVO = ConvertUtils.convertPage(pageDTO, QueryUserWalletInfoPageRespVO.class);
        logger.info(">>>> 当前queryUserWalletInfo响应内容：{} <<<", (null != pageVO ? JSONObject.toJSONString(pageVO) : ""));
        return ResponseVO.with(pageVO);
    }

    /**
     * 修改userWalletInfo信息
     *
     * @return
     */
    @NotNeedAccess
    @PostMapping(value = "/updateUserWalletInfo", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "修改userWalletInfo信息(肖博)", httpMethod = "POST", notes = "修改userWalletInfo信息(肖博)")
    public ResponseVO<UpdateUserWalletInfoRespVO> updateUserWalletInfo(@RequestBody @Valid UpdateUserWalletInfoReqVO reqVo, BindingResult bindingResult) {
        logger.info(">>>> 当前updateUserWalletInfo请求参数：{} <<<", (null != reqVo ? JSONObject.toJSONString(reqVo) : ""));
        UpdateUserWalletInfoReqDTO updateUserWalletInfoReqDTO = ConvertUtils.convert(reqVo, UpdateUserWalletInfoReqDTO.class);
        UpdateUserWalletInfoRespDTO updateUserWalletInfoRespDTO = iUserWalletInfoService.updateUserWalletInfo(updateUserWalletInfoReqDTO);
        UpdateUserWalletInfoRespVO updateUserWalletInfoRespVO = ConvertUtils.convert(updateUserWalletInfoRespDTO, UpdateUserWalletInfoRespVO.class);
        logger.info(">>>> 当前updateUserWalletInfo响应内容：{} <<<", (null != updateUserWalletInfoRespVO ? JSONObject.toJSONString(updateUserWalletInfoRespVO) : ""));
        return ResponseVO.with(updateUserWalletInfoRespVO);
    }

}
